<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>五子棋</title>
    <style>
        #board {
            display: grid;
            grid-template-columns: repeat(15, 40px);
            grid-template-rows: repeat(15, 40px);
            gap: 1px;
        }
        .cell {
            width: 40px;
            height: 40px;
            border: 1px solid #ccc;
            background-color: #f0f0f0;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        .black {
            background-color: black;
            border-radius: 50%;
            width: 30px;
            height: 30px;
        }
        .white {
            background-color: white;
            border: 2px solid black;
            border-radius: 50%;
            width: 30px;
            height: 30px;
        }
    </style>
</head>
<body>
    <h1>五子棋</h1>
    <div id="board"></div>
    <script>
        const BOARD_SIZE = 15;
        const board = document.getElementById('board');
        let currentPlayer = 1;  // 1: black, 2: white

        // 创建棋盘
        for (let i = 0; i < BOARD_SIZE; i++) {
            for (let j = 0; j < BOARD_SIZE; j++) {
                const cell = document.createElement('div');
                cell.classList.add('cell');
                cell.dataset.row = i;
                cell.dataset.col = j;
                cell.addEventListener('click', () => makeMove(i, j, cell));
                board.appendChild(cell);
            }
        }

        // 玩家落子
        function makeMove(row, col, cell) {
            if (cell.children.length > 0) return; // 已经有棋子
            const piece = document.createElement('div');
            if (currentPlayer === 1) {
                piece.classList.add('black');
            } else {
                piece.classList.add('white');
            }
            cell.appendChild(piece);
            currentPlayer = currentPlayer === 1 ? 2 : 1;

            // 发送数据给后端（可通过AJAX或Fetch API实现与C后端的通信）
        }
    </script>
</body>
</html>
fetch('/api/move', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
    },
    body: JSON.stringify({ row: row, col: col, player: currentPlayer }),
})
.then(response => response.json())
.then(data => {
    console.log(data);  // 处理后端返回的数据
});

